import {Injectable} from '@angular/core';
import {adSystemApiUrl} from '../../../../config/api';
import {Http, Headers, RequestOptions, RequestOptionsArgs} from '@angular/http';
import {HttpService} from '../../../lib/service/http.service';

@Injectable()
export class TempManageService {

  constructor(private httpService: HttpService) {
  }

  // 获取自定义通知消息列表
  getJobList(page: number, pagesize: number,stage:number = 0,keyword: string = '') {
    const url = `${adSystemApiUrl}/v2/member/template/job_list_v2?page=${page}&pagesize=${pagesize}&stage=${stage}&keyword=${keyword}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 获取商品列表
  getGoodsList(applet_uuid: string,
               page: number,
               pageSize: number,
               applet_goods_category_id?: number,
               status?: string, order?: string,
               keyword?: string) {
    const _applet_goods_category_id = applet_goods_category_id || '',
      _status = (status === '选择商品状态' ? '' : status) || '',
      _keyword = keyword || '';
    const _order = (order === 'none' ? '' : order) || '';
    const url = `${adSystemApiUrl}/v1/member/goods/list` +
      `?applet_uuid=${applet_uuid}&applet_goods_category_id=${_applet_goods_category_id}` +
      `&order=${_order}&status=${_status}&keyword=${_keyword}&page=${page}&pageSize=${pageSize}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 获取商品绑定了哪些分类
  getbindListAll(goods_id) {
    const url = `${adSystemApiUrl}/v1/member/applet_goods_category_relation/bindListAll?goods_id=${goods_id}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 活动管理列表
  getActivityList(page,
                  pageSize,
                  stage,
                  type) {
    const url = `${adSystemApiUrl}/v2/member/activity/list?page=${page}&pageSize=${pageSize}&stage=${stage}&type=${type}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 发送自定义消息模板
  postJob(item) {
    const url = `${adSystemApiUrl}/v1/member/template/add_batch_job`,
      data = item;
    return this.httpService.httpPostAuth(url, data).map(rs => rs);
  }

  // 获取卡券列表
  getCouponList(page: number,
                pageSize: number,
                keyword: string) {
    const url = `${adSystemApiUrl}/v2/member/card_coupons/list`;
    const headers = new Headers({'Content-Type': 'application/json'});
    const options = new RequestOptions({headers: headers});
    const body = JSON.stringify({
      page: page,
      pageSize: pageSize,
      keyword: keyword
    });
    return this.httpService.httpPostAuth(url, body, options).map(rs => rs);
  }
}
